from django import forms
from django.core.validators import RegexValidator

from web.utils.encrypt import md5


class LoginForm(forms.Form):
    username = forms.CharField(
        required=True,
        label='用户名',
        widget=forms.TextInput(attrs={"class": "form-control", "placeholder": "用户名"})
    )
    password = forms.CharField(
        label='密码',
        # validators=[RegexValidator(r'^[0-9]+$', '请输入数字')],
        widget=forms.PasswordInput(attrs={"class": "form-control", 'placeholder': '密码'}, render_value=True)
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def clean_password(self):
        return md5(self.cleaned_data.get('password'))
